using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using DevExpress.Utils;
using DevExpress.XtraNavBar.ViewInfo;
using DevExpress.XtraNavBar;

namespace DevExpress.Demos.DemoCenter {
	public class CustomNavLinkPainter : Office2NavLinkPainter {
		public CustomNavLinkPainter(NavBarControl navBar)
			: base(navBar) {
		}
		protected override void DrawLinkImageBorder(DevExpress.Utils.Drawing.ObjectInfoArgs e, Rectangle r) {
		}
	}
	public class CustomViewInfoRegistrator : Office2ViewInfoRegistrator {
		public override string ViewName {
			get {
				return "CustomView";
			}
		}
		public override BaseNavLinkPainter CreateLinkPainter(NavBarControl navBar) {
			return new CustomNavLinkPainter(navBar);
		}
	}
	public class BaseButton : PictureBox {
		public event EventHandler ButtonClick;
		internal ImageCollection images = null;
		public BaseButton() {
			this.BackColor = Color.Transparent;
			this.SizeMode = PictureBoxSizeMode.AutoSize;
			CreateImages();
			this.Image = images.Images[0];
		}

		protected virtual void CreateImages() {
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public new Image Image {
			get { return base.Image; }
			set { base.Image = value; }
		}

		protected override void OnMouseEnter(EventArgs e) {
			base.OnMouseEnter(e);
			this.Image = images.Images[1];
		}

		protected override void OnMouseLeave(EventArgs e) {
			base.OnMouseLeave(e);
			this.Image = images.Images[0];
		}

		protected override void OnMouseDown(MouseEventArgs e) {
			base.OnMouseDown(e);
			if(e.Button != MouseButtons.Left) return;
			this.Image = images.Images[2];
		}

		protected override void OnMouseUp(MouseEventArgs e) {
			base.OnMouseUp(e);
			if(e.Button != MouseButtons.Left) return;
			if(new Rectangle(0, 0, this.Width, this.Height).Contains(new Point(e.X, e.Y))) {
				this.Image = images.Images[1];
				RaiseButtonClick();
			}
			else {
				this.Image = images.Images[0];
			}
		}

		private void RaiseButtonClick() {
			if(ButtonClick != null)
				ButtonClick(this, EventArgs.Empty);
		}
	}
	public class CloseButton : BaseButton {
		protected override void CreateImages() {
			images = DevExpress.Utils.Controls.ImageHelper.CreateImageCollectionFromResources("DemoCenter.close_buttons.png", typeof(BaseButton).Assembly, new Size(33, 18));
		}
	}
	public class MinimizeButton : BaseButton {
		protected override void CreateImages() {
			images = DevExpress.Utils.Controls.ImageHelper.CreateImageCollectionFromResources("DemoCenter.minimize_buttons.png", typeof(BaseButton).Assembly, new Size(34, 18));
		}
	}
}
